package com.gmrz.uaf.crypto.sm;
import com.gmrz.util.Convert;

public class SM3Utils {


	public static boolean verifySM3Hash(byte[] sourceData,String base64Hash) {
		SM3Digest sm3 = new SM3Digest();
		sm3.update(sourceData, 0, sourceData.length);
		byte[] md = new byte[32];
		sm3.doFinal(md, 0);
		String sourceBase64 = Convert.toBase64(md);
		return sourceBase64.equals(base64Hash);
	}


	public static byte[] doSM3Hash(byte[] sourceData) {
		SM3Digest sm3 = new SM3Digest();
		sm3.update(sourceData, 0, sourceData.length);
		byte[] md = new byte[32];
		sm3.doFinal(md, 0);
		return md;
	}

	public static void main(String[] args){
//		String sourceData="12345678";  //4D59306C7397E06DE3CD82A14A926FBAFED44352AD3EF88A06F5CBE600AF3DCF
//		verifySM3Hash(Convert.fromHex(sourceData),"");
		String testSource = "123456test";
		byte[] bytes = doSM3Hash(testSource.getBytes());
		System.out.println(Convert.toBase64(bytes));
	}

}
